
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Browser Detection with <code>UA</code></title>

<style type="text/css">
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
	margin:0;
	padding:0;
}
</style>

<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" />
<script type="text/javascript" src="../../build/yui/yui-debug.js"></script>


<!--begin custom header content for this example-->
<style type="text/css">
    #dd1,#dd2 {
        position: relative;
        margin: 1em 1em 0;
        width: 175px;
        float: left;
        cursor: move;
    }

    #demo p {
        position: relative;
        padding: 0.1em;
        margin: 0;
        z-index: 20;
    }

    #dd1 p {
        border: 10px solid #ccc;
        background-color: #eee;
    }

    #dd2 p {
        border: 10px solid #e76300;
        background-color: #fff5df;
    }

    #demo .shim {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        margin: 0;
        padding: 0;
        border: 0;
        z-index: 10;
    }
</style>

<!--end custom header content for this example-->

</head>

<body class="yui3-skin-sam  yui-skin-sam">

<h1>Browser Detection with <code>UA</code></h1>

<div class="exampleIntro">
	<p>This example demonstrates how to access YUI's built-in user-agent
information to learn things about the environment in which your code
is running.  This includes information like what browser, version, and
operating system are being used; it also includes context information
like whether you're code is running on a mobile browser, running in a
secure page, or running under Adobe Air or Google Caja.</p>  

<p><strong>Note:</strong> We strongly recommend using feature
detection rather than user-agent sniffing to fork code. Fork on the
user-agent information only when absolutely necessary to do so (for 
example, in cases where browsers do not report their own capabilities
accurately).</p>
			
</div>

<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->

<pre style="margin-bottom: 1em">
UA properties set for your browser:
</pre>
<div id="demo">
</div>
<script type="text/javascript">

YUI({filter:"debug", logInclude: {example:true}}).use("node",
// This method is in the core of the library, so we don't have to use() any
// additional modules to access it.  However, this example requires 'node'.
function(Y) {
    var results = Y.one('#demo'), ua = '', patform = '';

    Y.each(Y.UA, function(v, k) {
        var info = k + ': ' + v;
        results.set('innerHTML', results.get('innerHTML') + 
            '<p>' + info + '</p>');

        if (v) {
            if (Y.Lang.isNumber(v)) {
                ua = info;
            } else {
                platform = v;
            }
        }
    });

    results.set('innerHTML', results.get('innerHTML') + 
        '<p>Your browser is ' + ua + ', ' + platform + '</p>');
});

</script>

<!--END SOURCE CODE FOR EXAMPLE =============================== -->

</body>
</html>
